package com.game.sprite;

import org.jbox2d.dynamics.Body;
import org.jbox2d.dynamics.World;

import android.graphics.Bitmap;
import android.graphics.Canvas;

import com.game.utils.JBox2dUtil;


/**
* @author oven:
* @version 创建时间：2012-10-8 上午10:11:20
* 
*/
public class BasicJboxShape extends BasicPhysicalSprite{
	Bitmap bitmap;

	/**
	 * 创建一个圆形
	 * @param world
	 * @param x
	 * @param y
	 * @param radius
	 * @param isStatic
	 */
	public BasicJboxShape(World world,float x,float y,float radius,boolean isStatic) {
		this(JBox2dUtil.createCircle(x, y, radius, world, isStatic));
		setWidth(radius*2);
		setHeight(radius*2);
	}
	
	/***
	 * 创建一个盒子
	 * @param world
	 * @param x
	 * @param y
	 * @param width
	 * @param height
	 * @param isStatic
	 */
	public BasicJboxShape(World world,float x,float y,float width,float height,boolean isStatic) {
		this(JBox2dUtil.createBox(x, y, width, height, world, isStatic));
	}
	
	/**
	 * 创建一个多边形
	 * @param world
	 * @param x
	 * @param y
	 * @param vertexs
	 * @param isStatic
	 */
	public BasicJboxShape(World world,float x,float y,float vertexs[],boolean isStatic) {
		this(JBox2dUtil.createShape(vertexs, x, y, world, isStatic));
	}
	
	public BasicJboxShape(Body body) {
		super(body.getWorld());
		phySicalbody=body;
		phySicalbody.m_userData=this;
		setWidthHeightWithVertexs(phySicalbody);
		updatePost();
	}
	
	public void setBitmap(Bitmap bmp){
		bitmap=bmp;
	}

	@Override
	public void paint(Canvas canvas) {
		if(bitmap!=null){
			canvas.drawBitmap(bitmap, getPostX(),getPostY(), paint);
		}
	}
}

